package cn.kimming.wms.web.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionContext;

import cn.kimming.wms.anno.RequiredPermission;
import cn.kimming.wms.domain.JsonMsg;
import cn.kimming.wms.query.QueryObject;
import cn.kimming.wms.service.IPermissionService;
import lombok.Getter;

@Controller("permissionAction")
@Scope("prototype")
public class PermissionAction extends BaseAction{

	private static final long serialVersionUID = 1486310761736142961L;
	
	@Autowired
	private IPermissionService permissionService;

	@Getter
	private QueryObject qo = new QueryObject();
	
	@Override
	@RequiredPermission("权限列表")
	public String execute() {
		try {
			ActionContext.getContext().put("objs", permissionService.query(qo));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return LIST;
	}
	
	@RequiredPermission("权限加载")
	public String load() {
		try {
			permissionService.load();
			putJSON(new JsonMsg(true,"加载成功"));
		} catch(Exception e) {
			e.printStackTrace();
			putJSON(new JsonMsg(false,"系统异常,加载失败!"));
		}
		return NONE;
	}

}
